local shubian = fk.CreateSkill{
    name = "xiaobai__shubian"
}
Fk:loadTranslationTable{
    ["xiaobai__shubian"] = "纾边",
    [":xiaobai__shubian"] = "结束阶段，你可令任意名体力值不大于你的角色可以同时展示手牌并弃置其中的伤害牌，若展示者/未展示者唯一，则你令其摸未展示角色数量张牌/展示其的手牌且可以用这些牌对其发动“斩威”。",
    ["#xiaobai__shubian"] = "纾边：你可令任意名体力值不大于你的角色同时选择，是否展示手牌并弃置其中的伤害牌",
    ["#xiaobai__shubian-show"] = "纾边：是否展示手牌并弃置其中的伤害牌",
}

shubian:addEffect(fk.EventPhaseEnd, {
    can_trigger = function (self, event, target, player, data)
        return player == target and target:hasSkill(shubian.name) and player.phase == Player.Finish
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function (cp)
            return cp.hp <= player.hp
        end)
        if #targets > 0 then
            local tos = room:askToChoosePlayers(player, {
                min_num = 1,
                max_num = #targets,
                skill_name = shubian.name,
                targets = targets,
                prompt = "#xiaobai__shubian"
            })
            if #tos > 0 then
                event:setCostData(self, { tos = tos })
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local tos = event:getCostData(self).tos
        local responder = {}
        local req = Request:new(tos, "AskForSkillInvoke")
        req.receive_decode = false
        req.focus_text = shubian.name
        for _, p in ipairs(tos) do
            req:setData(p, { shubian.name, "#xiaobai__shubian-show" })
        end
        req:ask()

        for index, cp in ipairs(tos) do
            local choice = req:getResult(cp)
            if choice ~= "" then
                table.insert(responder, cp)
                cp:showCards(cp:getCardIds("h"))
                local cards = table.filter(cp:getCardIds("h"), function (cardID)
                    return Fk:getCardById(cardID).is_damage_card == true
                end)
                room:throwCard(cards, shubian.name, cp, cp)
            end
        end

        if #responder == 1 then
            responder[1]:drawCards(#tos - 1, shubian.name)
        end
        if #tos - #responder == 1 then
            local cp = table.filter(tos, function (element)
                return not table.contains(responder, element)
            end)[1]
            local cards1, cards2 = cp:getCardIds("h"), table.filter(cp:getCardIds("h"), function (cardID)
                return Fk:getCardById(cardID).is_damage_card == true
            end)
            cp:showCards(cards1)

            room:askToUseActiveSkill(player, {
                skill_name = "xiaobai__zhanwei",
                extra_data = {
                    xiaobai__shubian = cp.id,
                    expandPile = cards1,
                    cardIds = cards2,
                },
                prompt = "#xiaobai__zhanwei-shubian::"..cp.id
            })
        end
    end,
})

return shubian